/*
 * @lc app=leetcode.cn id=500 lang=javascript
 *
 * [500] 键盘行
 */

// @lc code=start
/**
 * @param {string[]} words
 * @return {string[]}
 */
var findWords = function(words) {
    let arr = ['qwertyuiop', 'asdfghjkl', 'zxcvbnm']
    let result = []
    for (let index1 = 0; index1 < words.length; index1++) {
        const str = words[index1];
        const lowerStr = str.toLocaleLowerCase()
        let first = -1
        if (arr[0].includes(lowerStr[0])) {
            first = 0
        } else if (arr[1].includes(lowerStr[0])) {
            first = 1
        } else if (arr[2].includes(lowerStr[0])) {
            first = 2
        }
        let flag = true
        for (let index2 = 1; index2 < lowerStr.length; index2++) {
            const char = lowerStr[index2];
            if (!arr[first].includes(char)) {
                flag = false
                break
            }
        }
        if (flag) {
            result.push(str)
        }
    }
    return result
};
// @lc code=end

